package com.itzz.spring_zhoneHeng.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itzz.spring_zhoneHeng.pojo.Book;
import com.itzz.spring_zhoneHeng.pojo.BookShelf;
import com.itzz.spring_zhoneHeng.pojo.Chapters;
import org.apache.ibatis.annotations.*;

import java.util.List;

//书架
@Mapper
public interface BookShelfDao extends BaseMapper<Book> {
    //1.查询我的书架的所有书籍
    public List<BookShelf> queryAllBookShelf(@Param("bookName")String bookName,
            @Param("author") String author,
            @Param("category") String category,
            @Param("vip") Integer vip,
            @Param("bsids") Integer[] bsids);

    //修改书架的状态
//    @Update("update book set bookshelf=#{bookshelf} where id=#{bookid}")
//    public int updateBookShelf(@Param("bookid") Integer bookid,Integer bookshelf);


    //往书架里添加书籍
    int addBookShelf(BookShelf bookShelf);


    //添加书架和书籍的关联表
    @Insert("insert into b_bs(bookid,bsid) values(#{bookid},#{bsid})")
    int addBookShelfAndBook(@Param("bookid") Integer bookid, @Param("bsid") Integer bsid);


    //根据id删除书架和书籍的关联表
    @Delete("delete from b_bs where bsid=#{bsid}")
    int deleteBookShelfAndBook(Integer bsid);

    //根据id删除书架书籍
    @Delete("delete from bookshelf where id=#{id}")
    int deleteBookShelf(Integer id);

    //根据bookid 查询b_bs  中的bsid
    @Select("select bsid from b_bs where bookid=#{bookid}")
    Integer queryBookShelfId(Integer bookid);
    //根据bsid   查询bookshelf(id)  中的对应的书籍是否存在
    @Select("select * from bookshelf where id=#{bsid}")
    BookShelf queryBookShelfById(Integer bsid);

    //根据uid和bsid添加表u_bs (用户和书架的关联表)
    @Insert("insert into u_bs(uid,bsid) values(#{userid},#{bsid})")
    int addUserAndBookShelf(@Param("userid") Integer userid, @Param("bsid") Integer bsid);

    //根据uid 和bsid添加表u_bs (用户和书架的关联表)
    @Insert("insert into u_bs(uid,bsid) value(#{uid},#{bsid})")
    int addUserAndBookShelf2(@Param("uid") Integer uid, @Param("bsid") Integer bsid);


    //根据bsid  删除u_bs表
    @Delete("delete from u_bs where bsid=#{bsid}")
    int delU_BS(Integer bsid);

    //根据用户id 查询表u_bs中的bsid
    @Select("select bsid from u_bs where uid=#{uid}")
    List<Integer> queryBsid(Integer uid);

    //根据bsid 查询b_bs  中的bookid
    List<Integer> queryBookId(Integer[] bsids);

    //根据传输的书架id  查询书架书籍的详情
    @Select("select * from bookshelf where id=#{bookShelfId}")
    BookShelf queryBookShelfById2(Integer bookShelfId);


    //修改书架的信息
    @Update("update bookshelf set book_name=#{bookName},author=#{author},introduce=#{introduce},path=#{path},vip=#{vip} where id=#{id}")
    int updateBookShelf(BookShelf bookShelf);


   //根据bookid  查询数组 chapids  根据chapids  查询表chapters
    @Select("select chapid from b_chap where bookid=#{bookId}")
    List<Integer> queryChapids(Integer bookId);

    //根据bookshelfId 查询表 b_bs表的 bookid
    @Select("select bookid from b_bs where bsid=#{bsid}")
    Integer queryBookIdByBsid(Integer bsid);


    //根据o_b 表中的bookid 查询List<Interger> oid
    @Select("select oid from o_b where bookid=#{bookId}")
    List<Integer> queryOid(Integer bookId);


}
